using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Input.Touch;
namespace WindowsGame4
{
    public class Turret : Enemy
    {
        public float damage;
        public float offsetAngle;
        public GameObject gun;
        public const float shootDistance = 300;
        public Turret()
            : base()
        {
            texture = GameManager.turret;
            gun = new GameObject();
            gun.texture = GameManager.turretGun;
            //gun.scale = new Vector2(1, .2f);
            gun.bCollides = false;
            bCollides = true;
            bMoves = false;
            projectileSpeed = 50;
            GameManager.AddObject(gun);
            shootingTime.timeInterval = .2f;
            damage = 2;
        }
        public override void Update(float time)
        {
            base.Update(time);
            if (attachTarget != null)
                pos = attachTarget.pos + GetDir(offsetAngle + attachTarget.angle) * attachTarget.GetRadius();
            pos = pos;
            AI();
        }
        public override void AI()
        {
            base.AI();
            Vector2 dir = GameManager.player.pos - pos;
            float distance = dir.Length();
            if (distance > 0)
                dir.Normalize();
            float angle = GameObject.GetAngle(dir);
            gun.pos = pos + dir * gun.GetRadius();
            gun.angle = angle - 180;
            this.angle = offsetAngle + attachTarget.angle+90;
        }
        public override void Shoot()
        {
            base.Shoot();
            GameManager.turretShoot.Play();
            Vector2 dir = GameManager.player.pos - pos;
            if (dir.Length() > 0)
                dir.Normalize();
            Projectile p = new Projectile();
            p.hit = Projectile.HitType.Player;
            p.pos = pos;
            p.color = new Vector4(0, 1, 1, 1);
            p.angle = GetAngle(dir);
            //p.scale = new Vector2(.5f);
            p.bBlocks = false;
            p.damage = damage;
            p.vel = dir * projectileSpeed;
            GameManager.AddObject(p);
        }
        public override void OnDeath()
        {
            base.OnDeath();
            gun.bDead = true;
        }
    }
}
